#include "LLogicReward.h"
#include "common/PLog.h"

#include "LLogicProperty.h"

CLLogicReward::CLLogicReward(void)
{
}


CLLogicReward::~CLLogicReward(void)
{
}

void CLLogicReward::LogicInit() {
	AddLogicType(GLSLTRewardPropertyType);
	AddLogicType(GLSLTRewardEntityType);
}

bool CLLogicReward::CatchLogic(const ProtocolBase *head, char * data, uint32_t len, void * connect) {
	if (!this->ExistLogicType(head->m_Logic))
		return false;
	if (head->m_From == GLPFromServer) {
		switch (head->m_Logic) {
		case GLSLTRewardPropertyType:
			switch (head->m_Action) {
			case GLPASet:
				onPropertyReward(head, data, len);
				break;
			default:
				break;
			}
			break;
		case GLSLTRewardEntityType:
			switch (head->m_Action) {
			case GLPASet:
				onEntityReward(head, data, len);
				break;
			default:
				break;
			}
			break;
		default:
			break;
		}
	} else {

	}
	
	return true;
}

void CLLogicReward::onPropertyReward(const ProtocolBase *head, char * data, uint32_t len) {
	PropertyReward* tPropertyR = (PropertyReward*)(data);

	CLLogicProperty tLogicProperty;
	tLogicProperty.AddProperty(m_Oneself->GetProperty(), tPropertyR->m_MasterRealReward.m_RewardCount, tPropertyR->m_MasterRealReward.m_Reward);
	tLogicProperty.AddProperty(m_Oneself->GetProperty(), tPropertyR->m_MasterExtraReward.m_RewardCount, tPropertyR->m_MasterExtraReward.m_Reward);

	if (tPropertyR->m_BodyId > 0) {

	}
}

void CLLogicReward::onEntityReward(const ProtocolBase *head, char * data, uint32_t len) {
	EntityReward* tEntityR = (EntityReward*)(data);
	CGLPrivatePack* tPack = m_Oneself->GetContainerPack();
	for (uint8_t i = 0; i != tEntityR->m_Reward.m_RewardCount; ++i) {
		int32_t tRet = tPack->AutoGoods(tEntityR->m_Reward.m_Reward[i]);
		if (tRet != CommonErrnoSucceed) {
			CCLOG("pack|set|error|%d", tRet);
		}
	}
}
